$(function() {
    var definedData = [];
    definedData.auth = "@(Request.Cookies[FormsAuthentication.FormsCookieName]==null ? string.Empty : Request.Cookies[FormsAuthentication.FormsCookieName].Value)";
    definedData.ASPSESSID = "@Session.SessionID";
    definedData.fileTypeExts = "*.jpg;*.jpeg;*.png;*.mp4;";    //上传类型
    definedData.uploader = "/UploadHandler.ashx";    //后台处理路径
    definedData.fileSizeLimit = "100MB";  //上传大小
    definedData.fileObjName = "file_upload";    //控件名
    definedData.queueSizeLimit = 1;      //允许上传个数文件
    var data = { 'ASPSESSID': definedData.ASPSESSID, 'AUTHID': definedData.auth };    //firefox用swf上传丢失session

    var errorData = [];
    errorData.err100 = "文件个数超出系统限制，只允许上传" + definedData.queueSizeLimit + "个文件！";
    errorData.err110 = "文件超出系统限制的大小，限制文件大小" + definedData.fileSizeLimit + "！";
    errorData.err120 = "文件大小异常！";
    errorData.err130 = "文件类型不正确，只允许上传后缀名" + definedData.fileTypeExts + "！";


    $("#file_upload").uploadify({
        swf           : swf,
        uploader      : image_upload_url,
        buttonText    : '图片上传',
        fileTypeDesc  : 'Image files',
        fileObjName   : 'file',
        fileTypeExts  : '*.gif;*.jpg;*.jpeg;*.png',
        onUploadSuccess : function(file, data, response) {
            // 我们需要扩展内容
            alert('文件上传成功');
            if(response) {
                console.log(response);
                console.log(data);
                var obj = JSON.parse(data);
                $('#upload_org_code_img').attr("src", obj.data);
                $('#file_upload_image').attr("value", obj.data);
                $('#upload_org_code_img').show();
            }
        },
        onUploadError: function(file, errorCode, errorMsg){
            console.log(file);
            console.log(errorCode);
            console.log(errorMsg);
        },//返回一个错误，选择文件的时候触发
        'onSelectError': function (file, errorCode, errorMsg) {
            switch (errorCode) {
                case -100:
                    alert(errorData.err100);
                    break;
                case -110:
                    alert(errorData.err110);
                    break;
                case -120:
                    alert(errorData.err120);
                    break;
                case -130:
                    alert(errorData.err130);
                    break;
            }
        },
    });
    $("#file_upload2").uploadify({
        swf           : swf,
        uploader      : image_upload_url,
        buttonText    : '视频文件上传',
        fileTypeDesc  : 'Image files',
        fileObjName   : 'file',
        fileTypeExts  : '*.mp4',
        successTimeout: 180,
        onUploadSuccess : function(filefile, data, response) {
            // 我们需要扩展内容
            console.log(filefile);
            console.log(response);
            console.log(data);
            if(response) {
            alert('文件上传成功');
                console.log(data);
                var obj = JSON.parse(data);
                $('#upload_org_code_img2').attr("src", obj.data);
                console.log($('#file_upload_image2'));
                console.log(data);
                console.log(obj);
                console.log(obj.data);
                $('#file_upload_image2').attr("value", obj.data);
                $('#file_upload_image2').val(obj.data);
                $('#upload_org_code_img2').show();
            }
        },
        onUploadError: function(file, errorCode, errorMsg){
            console.log(file);
            console.log(errorCode);
            console.log(errorMsg);

        },//返回一个错误，选择文件的时候触发
        'onSelectError': function (file, errorCode, errorMsg) {
            switch (errorCode) {
                case -100:
                    alert(errorData.err100);
                    break;
                case -110:
                    alert(errorData.err110);
                    break;
                case -120:
                    alert(errorData.err120);
                    break;
                case -130:
                    alert(errorData.err130);
                    break;
            }
        },
    });
    $("#file_upload3").uploadify({
        swf           : swf,
        uploader      : image_upload_url,
        buttonText    : '图片上传',
        fileTypeDesc  : 'Image files',
        fileObjName   : 'file',
        fileTypeExts  : '*.gif;*.jpg;*.png',
        onUploadSuccess : function(file, data, response) {
            alert('文件上传成功');
            // 我们需要扩展内容
            if(response) {
                console.log(response);
                console.log(data);
                var obj = JSON.parse(data);
                $('#upload_org_code_img3').attr("src", obj.data);
                $('#file_upload_image3').attr("value", obj.data);
                $('#upload_org_code_img3').show();
            }
        },
        onUploadError: function(file, errorCode, errorMsg){
            console.log(file);
            console.log(errorCode);
            console.log(errorMsg);

        },//返回一个错误，选择文件的时候触发
        'onSelectError': function (file, errorCode, errorMsg) {
            switch (errorCode) {
                case -100:
                    alert(errorData.err100);
                    break;
                case -110:
                    alert(errorData.err110);
                    break;
                case -120:
                    alert(errorData.err120);
                    break;
                case -130:
                    alert(errorData.err130);
                    break;
            }
        },
    });
});